home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / sox / st.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  6KB  |  226 lines

  1. /*
  2.  * July 5, 1991
  3.  * Copyright 1991 Lance Norskog And Sundry Contributors
  4.  * This source code is freely redistributable and may be used for
  5.  * any purpose.  This copyright notice must be maintained. 
  6.  * Lance Norskog And Sundry Contributors are not responsible for 
  7.  * the consequences of using this software.
  8.  */
  9.  
  10. #ifdef VAXC
  11. #define IMPORT  globalref
  12. #define EXPORT  globaldef
  13. /*
  14.  * use the VAX C optimized functions 
  15.  */ 
  16. #define calloc  VAXC$CALLOC_OPT
  17. #define cfree   VAXC$CFREE_OPT
  18. #define free    VAXC$FREE_OPT
  19. #define malloc  VAXC$MALLOC_OPT
  20. #define realloc VAXC$REALLOC_OPT
  21. #else
  22. #define IMPORT  extern
  23. #define EXPORT 
  24. #endif
  25.  
  26.  
  27. /*
  28.  * Sound Tools sources header file.
  29.  */
  30.  
  31. #include <stdio.h>
  32.  
  33. #ifdef AMIGA
  34. #include "amiga.h"
  35. #endif /* AMIGA */
  36.  
  37. /*
  38.  * Handler structure for each format.
  39.  */
  40.  
  41. typedef struct format {
  42.     char    **names;    /* file type names */
  43.     int    (*startread)();            
  44.     int    (*read)();            
  45.     int    (*stopread)();        
  46.     int    (*startwrite)();            
  47.     int    (*write)();
  48.     int    (*stopwrite)();        
  49. } format_t;
  50.  
  51. IMPORT format_t formats[];
  52.  
  53. /* Signal parameters */
  54.  
  55. struct  signalinfo {
  56.     long        rate;        /* sampling rate */
  57.     int        size;        /* word length of data */
  58.     int        style;        /* format of sample numbers */
  59.     int        channels;    /* number of sound channels */
  60. };
  61.  
  62. /* Pipe parameters */
  63.  
  64. struct    pipeinfo {
  65.     FILE    *pout;            /* Output file */
  66.     FILE    *pin;            /* Input file */
  67. };
  68.  
  69. /*
  70.  *  Format information for input and output files.
  71.  */
  72.  
  73. #define    PRIVSIZE    50
  74.  
  75. struct soundstream {
  76.     struct    signalinfo info;    /* signal specifications */
  77.     char    swap;            /* do byte- or word-swap */
  78.     char    seekable;        /* can seek on this file */
  79.     char    *filename;        /* file name */
  80.     char    *filetype;        /* type of file */
  81.     char    *comment;        /* comment string */
  82.     FILE    *fp;            /* File stream pointer */
  83.     format_t *h;            /* format struct for this file */
  84.     char    priv[PRIVSIZE];        /* format's private data area */
  85. };
  86.  
  87. IMPORT struct soundstream informat, outformat;
  88. typedef struct soundstream *ft_t;
  89.  
  90. /* Size field */
  91. #define    BYTE    1
  92. #define    WORD    2
  93. #define    LONG    4
  94. #define    FLOAT    5
  95. #define DOUBLE    6
  96. #define IEEE    7        /* IEEE 80-bit floats.  Is it necessary? */
  97.  
  98. /* Style field */
  99. #define UNSIGNED    1    /* unsigned linear: Sound Blaster */
  100. #define SIGN2        2    /* signed linear 2's comp: Mac */
  101. #define    ULAW        3    /* U-law signed logs: US telephony, SPARC */
  102. #define ALAW        4    /* A-law signed logs: non-US telephony */
  103.  
  104. IMPORT char *sizes[], *styles[];
  105.  
  106. /*
  107.  * Handler structure for each effect.
  108.  */
  109.  
  110. typedef struct {
  111.     char    *name;            /* effect name */
  112.     int    flags;            /* this and that */
  113.     int    (*getopts)();        /* process arguments */
  114.     int    (*start)();        /* start off effect */
  115.     int    (*flow)();        /* do a buffer */
  116.     int    (*drain)();        /* drain out at end */
  117.     int    (*stop)();        /* finish up effect */
  118. } effect_t;
  119.  
  120. IMPORT effect_t effects[];
  121.  
  122. #define    EFF_CHAN    1        /* Effect can mix channels up/down */
  123. #define EFF_RATE    2        /* Effect can alter data rate */
  124. #define EFF_MCHAN    4        /* Effect can handle multi-channel */
  125.  
  126. struct effect {
  127.     char        *name;        /* effect name */
  128.     struct signalinfo ininfo;    /* input signal specifications */
  129.     struct signalinfo outinfo;    /* output signal specifications */
  130.     effect_t     *h;        /* effects driver */
  131.     char        priv[PRIVSIZE];    /* private area for effect */
  132. };
  133.  
  134. typedef struct effect *eff_t;
  135.  
  136. #ifdef    __STDC__
  137. #define    P1(x) x
  138. #define    P2(x,y) x, y
  139. #define    P3(x,y,z) x, y, z
  140. #define    P4(x,y,z,w) x, y, z, w
  141. #else
  142. #define P1(x)
  143. #define P2(x,y)
  144. #define P3(x,y,z)
  145. #define P4(x,y,z,w)
  146. #endif
  147.  
  148. /* Utilities to read and write shorts and longs little-endian and big-endian */
  149. unsigned short rlshort(P1(ft_t ft));            /* short little-end */
  150. unsigned short rbshort(P1(ft_t ft));            /* short big-end    */
  151. unsigned short wlshort(P2(ft_t ft, unsigned short us));    /* short little-end */
  152. unsigned short wbshort(P2(ft_t ft, unsigned short us));    /* short big-end    */
  153. unsigned long  rllong(P1(ft_t ft));            /* long little-end  */
  154. unsigned long  rblong(P1(ft_t ft));            /* long big-end     */
  155. unsigned long  wllong(P2(ft_t ft, unsigned long ul));    /* long little-end  */
  156. unsigned long  wblong(P2(ft_t ft, unsigned long ul));    /* long big-end     */
  157. /* Read and write words and longs in "machine format".  Swap if indicated.  */
  158. unsigned short rshort(P1(ft_t ft));            
  159. unsigned short wshort(P2(ft_t ft, unsigned short us));
  160. unsigned long  rlong(P1(ft_t ft));        
  161. unsigned long  wlong(P2(ft_t ft, unsigned long ul));
  162. /* Utilities to byte-swap values */
  163. unsigned short swapw(P1(unsigned short us));        /* Swap short */
  164. unsigned long  swapl(P1(unsigned long ul));        /* Swap long */
  165.  
  166. IMPORT void report(P2(char *, ...)), fail(P2(char *, ...));
  167.  
  168. #if    defined(SYSV) || defined(DOS) || defined(__STDC__)
  169. #define    bcopy(from, to, len)    memcpy(to, from, len)
  170. #define    index        strchr
  171. #define    rindex        strrchr
  172. #endif
  173.  
  174. typedef    unsigned int u_i;
  175. typedef    unsigned long u_l;
  176. typedef    unsigned short u_s;
  177.  
  178. #define    MAXRATE    50L * 1024            /* maximum sample rate */
  179.  
  180. #ifdef    unix
  181. /* Some wacky processors don't have arithmetic down shift, so do divs */
  182. #define LEFT(datum, bits)    (datum << bits)
  183. /* Most compilers will turn this into a shift if they can, don't worry */
  184. /* #define RIGHT(datum, bits)    (datum / (1L << bits)) /* use maybe? */
  185. #define RIGHT(datum, bits)    (datum >> bits)
  186. #else
  187. /* x86 & 68k PC's have arith shift ops and dumb compilers */
  188. #define LEFT(datum, bits)    (datum << bits)
  189. #define RIGHT(datum, bits)    (datum >> bits)
  190. #endif
  191.  
  192. #ifndef    M_PI
  193. #define M_PI    3.14159265358979323846
  194. #endif
  195.  
  196. #if    defined(unix) || defined(AMIGA)
  197. #define READBINARY    "r"
  198. #define WRITEBINARY    "w"
  199. #endif
  200. #ifdef    VMS
  201. #define READBINARY      "r", "mbf=16", "ctx=stm" 
  202. #define WRITEBINARY     "w", "ctx=stm"
  203. #endif
  204. #ifdef    DOS
  205. #define READBINARY    "rb"
  206. #define WRITEBINARY    "wb"
  207. #endif
  208.  
  209. /* Error code reporting */
  210. #ifdef    QNX
  211. #include <errno.h>
  212. #endif
  213.  
  214. #ifdef    unix
  215. #include <errno.h>
  216. extern errno;
  217. extern char *sys_errlist[];
  218. /* #if defined(i386) || !defined(__STDC__)
  219. #define strerror(errno)    sys_errlist[errno]
  220. #endif */
  221. #endif
  222.  
  223. #ifdef    DOS
  224. /* ??? */
  225. #endif
  226.